<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Map"%>
<%@page import="cookiesession.Product"%>
<%@page import="java.util.Collection"%>
<%@page import="cookiesession.CartShop"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
<script type="text/javascript">
	function change(id){
		//获取修改的数量
		var num = document.getElementById("num"+id).value;
		//跳转到修改页面
		location.href="Update.jsp?pid="+id+"&cnt="+num;
	}
</script>
</head>
<body>
<h3>我的购物车</h3>
	<table border="1" cellpadding="0" cellspacing="0" width="800px">
		<tr>
			<th>商品名</th>
			<th>单价</th>
			<th>数量</th>
			<th>小计</th>
			<th>操作</th>
		</tr>
		<%
			//获取session中的购物车
			CartShop cs = (CartShop)session.getAttribute("cs");
			Map<Integer, Product> mp = cs.getCarts();
			double count=0;
			for(Entry<Integer, Product> e:mp.entrySet()){
				Product p = e.getValue();
				double cnt = p.getPrice()*p.getCount();
				count +=cnt;
		%>
		<tr>
			<td><%=p.getName() %></td>
			<td><%=p.getPrice() %></td>
			<td><input id="num<%=p.getPid() %>" value="<%=p.getCount() %>">
				<input type="button" value="修改" onclick="change(<%=p.getPid() %>)"> 
			</td>
			<td><%=cnt %></td>
			<td><a href="">删除</a></td>
		</tr>
		<%} %>
	</table>
	<h5>总计金额：<%=count %>元</h5>
</body>
</html>